import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

class CacheImage extends StatelessWidget {
  const CacheImage({Key? key}) : super(key: key);
  Widget _imageWrapper(String imageUrl) {
    return SizedBox(
      width: 150,
      height: 200,
      child: CachedNetworkImage(
        imageUrl: imageUrl,
        fit: BoxFit.cover,
        placeholder: (context, url) => Image.asset('images/avatar.png'),
        errorWidget: (context, url, error) =>
            Image.asset('images/navbar/home_icon_a.png'),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      body: Container(
        child: Column(
          children: [
            Container(
              width: 350,
              height: 200,
              color: Colors.black,
              child: _imageWrapper(
                  'https://www.ld-seo.com/uploadfile/images/637f0862833cf1669269602.jpg'),
            ),
          ],
        ),
      ),
    ));
  }
}
